package dex.studio.compose.news.ui.activity

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import dex.studio.compose.news.ui.pages.NewsListPage
import dex.studio.compose.news.ui.pages.NewsDetailPage
import dex.studio.compose.news.ui.tools.NewsNavigation
import dex.studio.compose.news.ui.tools.Screen


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            when (val currentScreen = NewsNavigation.currentScreen.value) {
                //当前需要展示首页/列表页
                is Screen.ListPage -> NewsListPage(
                    onNewsListClick = { NewsNavigation.to(Screen.Detail(it)) })
                //当前需要展示详情页
                is Screen.Detail -> NewsDetailPage(currentScreen.newsBean)
            }
        }
    }

    override fun onBackPressed() {
        if (NewsNavigation.backAndReturnsIsLastPage()) {
            super.onBackPressed()
        }
    }
}
